<!-- 新增和编辑弹窗 -->
<template>
  <a-modal
    :width="800"
    :visible="visible"
    title="详情"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-descriptions bordered :column="2" size="default">
      <a-descriptions-item label="设备ID">{{ form.recordId }}</a-descriptions-item>
      <a-descriptions-item label="推送类型">{{ formatType }}</a-descriptions-item>
      <a-descriptions-item label="推送情况">{{ formatSendResult }}</a-descriptions-item>
      <a-descriptions-item label="推送时间">{{ formatTime }}</a-descriptions-item>
      <a-descriptions-item label="操作者" :span="2">{{ form.createUserName }}</a-descriptions-item>
      <a-descriptions-item label="执行信息" :span="2">{{ form.msg }}</a-descriptions-item>
    </a-descriptions>
    <a-divider/>
    <a-collapse :active-key="['1']">
      <a-collapse-panel key="1" header="推送命令(16进制)">
        <p>{{ form.sendContent }}</p>
      </a-collapse-panel>
    </a-collapse>
    <a-divider/>
    <a-collapse :active-key="['1']">
      <a-collapse-panel key="1" header="具体参数">
        <p>{{ form.updateData }}</p>
      </a-collapse-panel>
    </a-collapse>
  </a-modal>
</template>

<script>
  import { reactive, toRefs, watchEffect } from 'vue';
  import moment from 'moment';

  export default {
    name: 'DeviceSprayCtocabinetConfigQueueDetailNew',
    emits: ['update:visible'],
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 详情数据
      data: Object
    },
    setup(props, context) {
      const data = reactive({
        form: {}
      });

      const watch = watchEffect(() => {
        if (props.data) {
          data.form = Object.assign({}, props.data);
        }
      });

      const updateVisible = value => {
        context.emit('update:visible', value);
      };

      return {
      ...toRefs(data),
      watch,
      updateVisible
      };
    },
    computed : {
      formatType : function () {
        if (this.form.sceneDictate == 0) {
          return "推送时间到终端";
        } else if (this.form.sceneDictate == 4) {
          return "重启终端设备";
        } else if (this.form.sceneDictate == 5) {
          return "通知设备更新代码";
        } else if (this.form.sceneDictate == 6) {
          return "更新终端网关的握手间隔时间";
        } else if (this.form.sceneDictate == 7) {
          return "设置终端连接服务器的IP和端口";
        } else if (this.form.sceneDictate == 10) {
          return "设置终端服务器的域名和端口";
        } else if (this.form.sceneDictate == 9991) {
          return "设置参数(全局配置和各种参数配置)"
        } else if (this.form.sceneDictate == 32) {
          return "读取设备时间";
        } else if (this.form.sceneDictate == 37) {
          return "读取终端网关的握手间隔时间";
        } else if (this.form.sceneDictate == 56) {
          return "读取参数配置";
        } else if (this.form.sceneDictate == 34) {
          return "读取设备id和固件版本";
        } else if(this.form.sceneDictate == 38) {
          return "读取设备的SIM卡信息";
        }
      },
      formatSendResult : function() {
        if (this.form.isSend == 0) {
          return '未推送';
        } else if (this.form.isSend == 1) {
          return '推送中';
        } else if (this.form.isSend == 2) {
          return '已推送';
        } else if (this.form.isSend == 3) {
          if (this.form.feedback == 1) {
            return '已反馈(确认)';
          } else if (this.form.feedback == 2){
            return '已反馈(否认)';
          } else {
            return '已反馈(未知)';
          }
        } else if (this.form.isSend == 4) {
          return '失败';
        } else {
          return '-';
        }
      },
      formatTime : function() {
        if (this.form.sendTime) {
          return moment(this.form.sendTime * 1000).format('YYYY-MM-DD HH:mm:ss')
        } else {
          return '-';
        }
      }
    }
  };
</script>

<style scoped></style>
